#! env python
#-*- coding: utf-8 -*-

import requests

# Gitee API Base URL
API_URL = 'https://gitee.com/api/v5'

def create_repo(repo_name, description='', api_token=None):
    if api_token is None:
        import os
        api_token = os.environ['GITEE_TOKEN']
    headers = { "Authorization": f"token {api_token}", "Content-Type": "application/json" }
    data = { "name": repo_name, "description": description, "private": True }
    response = requests.post(f"{API_URL}/user/repos", json=data, headers=headers)
    if response.status_code == 201:
        print("创建仓库成功:", response.json())
    else:
        print(f"请求失败，状态码：{response.status_code}, 原因: {response.text}")


if __name__ == '__main__':
    repo_name = 'example-repo'
    description = 'A sample repository created via Python script.'
    create_repo(repo_name, description)
